#!/bin/sh
# usage: mkb ${percent}
# port of http://git.z3bra.org/mkb/file/mkb.c.html
# TODO: consider tying in the options here into themes.

# args
progress="$1"
size="$2"
char1="$3"
char2="$4"
sep="$5"
start="$6"
end="$7"

# defaults
progress=${progress:-30}
size=${size:-32}
char1="${char1:-━}"
char2="${char2:-━}"
sep="${sep:-╋}"
start="${start:-}"
end="${end:-}"

# some ideas
#char1="◼" sep="◼" char2="◻"
#char1="▰" sep="▰" char2="▱"

passed=false
content="${start}"

content="${content}${start}"
for i in $(seq 1 $size); do
    if [ "$(echo "$i < $progress / 100 * $size" | bc -l)" = 1 ]; then
        current="$char1"
    else
        $passed && current="$char2" || current="$sep"
        passed=true
    fi
    content="${content}${current}"
done
content="${content}${end}"
echo "$content"
